package org.millioncall.yueyoga.admin.export;

import java.util.List;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.millioncall.yueyoga.admin.model.Product;

public class ProductExportTemplate extends AbstractExcelExportTemplate {
	private List<Product> records;
	String[] titles = new String[] { "产品名称", "类型", "价格", "次数", "备注" };

	public ProductExportTemplate(List<Product> records) {
		this.records = records;
	}

	@Override
	public String[] getSheetNames() {
		return new String[] { "产品记录信息表" };
	}

	@Override
	public String[][] getTitles() {
		return new String[][] { titles };
	}

	@Override
	protected void buildBody(int sheetIndex) {
		Sheet sheet = getSheet(sheetIndex);
		int startIndex = this.getBodyStartIndex(sheetIndex);
		for (int i = 0; i < this.records.size(); i++) {
			Product record = this.records.get(i);

			Row row = sheet.createRow(i + startIndex);
			row.setHeight((short) 300);
			int index = 0;
			String lx = "";

			Integer intType = record.getType();
			String strType;
			if (intType == null) {
				strType = "";
			} else {
				strType = intType.toString();
			}

			if ("101".equals(strType)) {
				lx = "按次数";
			} else if ("102".equals(strType)) {
				lx = "按时间";
			} else if ("103".equals(strType)) {
				lx = "按金额";
			} else if ("104".equals(strType)) {
				lx = "年卡";
			} else if ("105".equals(strType)) {
				lx = "季卡";
			} else if ("106".equals(strType)) {
				lx = "月卡";
			} else if ("107".equals(strType)) {
				lx = "半月卡";
			} else if ("108".equals(strType)) {
				lx = "实时扣费";
			}
			createStyledCell(row, index++, record.getName() == null ? ""
					: record.getName().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, lx, this.bodyRowStyle);
			createStyledCell(row, index++, record.getPrice() == null ? ""
					: record.getPrice().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getCounts() == null ? ""
					: record.getCounts().toString(), this.bodyRowStyle);
			createStyledCell(row, index++, record.getRemarks() == null ? ""
					: record.getRemarks().toString(), this.bodyRowStyle);
		}
	}

	@Override
	public String[] getCaptions() {
		return new String[] { "产品记录信息表" };
	}
}
